﻿using System;
using Icinetic.FeedCategorySample.Entities;
using Icinetic.FeedCategorySample.ViewModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Icinetic.FeedCategorySample
{
    public sealed partial class MenuControl : UserControl
    {
        public MenuControl()
        {
            this.InitializeComponent();
        }

        void semanticZoomMenu_ViewChangeCompleted(object sender, SemanticZoomViewChangedEventArgs e)
        {
            semanticZoomMenu.ViewChangeCompleted -= semanticZoomMenu_ViewChangeCompleted;
        }

        private void SemanticZoom_ViewChangeStarted(object sender, SemanticZoomViewChangedEventArgs e)
        {
            if (((SemanticZoom)sender).IsZoomedInViewActive)
            {
                (DataContext as MainPageViewModel).State = MainPageStateEnum.ZoomInMenu;
                semanticZoomMenu.IsZoomedInViewActive = true;
                semanticZoomMenuPortrait.IsZoomedInViewActive = true;
            }
            else
            {
                (DataContext as MainPageViewModel).State = MainPageStateEnum.ZoomOutMenu;
                semanticZoomMenu.IsZoomedInViewActive = false;
                semanticZoomMenuPortrait.IsZoomedInViewActive = false;
            }
        }

        void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {
            RssItem target = e.ClickedItem as RssItem;
            (DataContext as MainPageViewModel).State = MainPageStateEnum.ZoomInMenu;
            Frame frame = Window.Current.Content as Frame;
            frame.Navigate(typeof(ArticlePage), target);
        }
    }
}
